import datetime
from flask import Blueprint
from flask import request
import random
import json

bp_coupon = Blueprint('coupon', __name__)


@bp_coupon.route('/add', methods=['POST', 'GET'])
def add():
    if request.method == 'POST':
        # 获取vue发过来的参加
        data = json.loads(request.data)
        code = datetime.dateime.strftime(datetime.dateime.now(), '%Y%m%d$H%m%S') + str(random.randint(10000, 99999))
        sql = 'insert into coupon(code,man,jian,stime,etime,total) calues(%s,%d,%d,%s,%s,%d)' % \
              (code, data['main'], data['jian'], data, ['stime'], data['etime'], data['total'])
        return '添加优惠'

    else:
        return '获取'
